<template>
  <div class="app-container">

    <u-page title="商户管理">
      <div slot="header">
<!--        <el-button type="primary" icon="el-icon-edit" @click="hdlOpen(newForm)">
          {{ textMap['create'] }}
        </el-button>-->
      </div>

      <u-filtered>
        <el-form ref="listQuery" :inline="true" :model="listQuery" class="search-form">

          <el-form-item label="商户分类" prop="classify">
            <el-input v-model="listQuery.classify" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="商户" prop="merchantName">
            <el-input v-model="listQuery.merchantName" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="商户编码" prop="merchantNo">
            <el-input v-model="listQuery.merchantNo" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="公司" prop="enterpriseName">
            <el-input v-model="listQuery.enterpriseName" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="公司编码" prop="enterpriseNo">
            <el-input v-model="listQuery.enterpriseNo" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="商户类型" prop="type">
            <el-input v-model="listQuery.type" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="合同编码" prop="contractNo">
            <el-input v-model="listQuery.contractNo" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="部门" prop="deptName">
            <el-input v-model="listQuery.deptName" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="listQuery.status" placeholder="请选择状态" style="width: 120px" clearable >
              <el-option value="" label="全部" />
              <el-option :value="1" label="启用" />
              <el-option :value="0" label="禁用" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-dropdown>
              <el-button type="primary">
                批量操作<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item :disabled="selectData.length===0" @click.native="hdlDel">批量删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-download" @click="hdlExport">导出</el-button>
          </el-form-item>
        </el-form>
      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      >
        <template v-slot:right>
          <el-table-column label="操作" align="center" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" @click="hdlEdit(row)">编辑</el-button>
              <el-button type="text" @click="hdlDelete(row.id, row.merchantName)">删除</el-button>
            </template>
          </el-table-column>
        </template>
      </u-table>

    </u-page>

    <u-dialog :title="textMap[dialogStatus]" :show.sync="dialogFormVisible" @confirm="dialogStatus==='create'?hdlCreate():hdlUpdate()">
      <el-form ref="dialogForm" :rules="rules" :model="dataForm" label-width="100px">

        <el-form-item prop="deptNo" label="部门编码">
          <el-input v-model="dataForm.deptNo" placeholder="部门编码" clearable :disabled="dialogStatus==='update'" />
        </el-form-item>

        <el-form-item prop="deptName" label="部门名称">
          <el-input v-model="dataForm.deptName" placeholder="部门名称" clearable />
        </el-form-item>

        <el-form-item prop="merchantName" label="商户名称">
          <el-input v-model="dataForm.merchantName" placeholder="商户名称" clearable />
        </el-form-item>

        <el-form-item prop="merchantNo" label="商户编码">
          <el-input v-model="dataForm.merchantNo" placeholder="商户编码" clearable />
        </el-form-item>

        <el-form-item prop="enterpriseName" label="公司名称">
          <el-input v-model="dataForm.enterpriseName" placeholder="公司名称" clearable />
        </el-form-item>

        <el-form-item prop="enterpriseNo" label="公司编码">
          <el-input v-model="dataForm.enterpriseNo" placeholder="公司编码" clearable />
        </el-form-item>

        <el-form-item prop="contractNo" label="合同编号">
          <el-input v-model="dataForm.contractNo" placeholder="合同编号" clearable />
        </el-form-item>

        <el-form-item prop="classify" label="商户分类">
          <el-input v-model="dataForm.classify" placeholder="商户分类" clearable />
        </el-form-item>

        <el-form-item prop="type" label="商户类型">
          <el-input v-model="dataForm.type" placeholder="商户类型" clearable />
        </el-form-item>

        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="dataForm.status">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item prop="note" label="备注">
          <el-input v-model="dataForm.note" type="textarea" placeholder="后台备注" clearable maxlength="200" show-word-limit />
        </el-form-item>

      </el-form>
    </u-dialog>

  </div>
</template>
<script>
export default {
  data() {
    return {
      api: this.$u.api.Merchant,
      // 表格
      columns: [
        {
          prop: 'classify',
          label: '商户分类'
        },

        {
          prop: 'merchantName',
          label: '商户'
        },
        {
          prop: 'merchantNo',
          label: '商户编码'
        },
        {
          prop: 'cashierNo',
          label: '收银员编号'
        },
        {
          prop: 'cashierName',
          label: '收银员名称'
        },
        {
          prop: 'enterpriseName',
          label: '公司'
        },
        {
          prop: 'enterpriseNo',
          label: '公司编码'
        },
        {
          prop: 'type',
          label: '商户类型'
        },
        {
          prop: 'contractNo',
          label: '合同编码'
        },
        {
          prop: 'deptName',
          label: '部门'
        },
        {
          prop: 'deptNo',
          label: '部门编码'
        },
        {
          prop: 'status',
          label: '状态',
          render: (h, params) => {
            if (params.row.status === 1) {
              return h('el-tag', { props: { type: 'success' }}, '已启用')
            } else {
              return h('el-tag', { props: { type: 'danger' }}, '禁用')
            }
          }
        },
        {
          prop: 'createdAt',
          label: '创建时间',
          timestamp: true
        }
      ],

      list: [],
      listLoading: true,
      listOptions: {
        mutiSelect: true, // boolean 是否多选
        stripe: true // boolean 斑马纹
      },
      listQuery: {
        pageNumber: 1,
        pageSize: 10,
        totalCount: 1,
        title: '',
        status: ''
      },

      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑商户',
        create: '新增商户'
      },
      dataForm: {},
      rules: {
        title: [
          { required: true, message: '请输入标题', trigger: ['blur'] }
        ]
      },
      // 删除选中数据
      selectData: [],
      newForm: {
        status: 1
      }
    }
  },
  created() {
    this.hdlList()
  }
}
</script>
